package com.ts.api.module.distribute.service.impl;

import com.gitee.apanlh.util.date.DateUtils;
import com.ts.api.module.distribute.dao.DistributeUvDao;
import com.ts.api.module.distribute.entity.DistributeGroupUv;
import com.ts.api.module.distribute.entity.DistributeUv;
import com.ts.api.module.distribute.entity.bo.DistributeLinkBO;
import com.ts.api.module.distribute.service.DistributeUvService;
import eu.bitwalker.useragentutils.UserAgent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 智能分配，子链接UVService业务层处理
 *
 * @author ts
 * @date 2023-09-13
 */
@Service
public class DistributeUvServiceImpl implements DistributeUvService {

    @Autowired
    private DistributeUvDao distributeUvDao;



    @Override
    public int insertGroupUv(String ip, UserAgent userAgent, Long groupId) {
        DistributeGroupUv groupUv = new DistributeGroupUv();
        groupUv.setCreateTime(DateUtils.currentTime());
        groupUv.setLoanDistributeGroupId(groupId);
        groupUv.setIp(ip);
        groupUv.setBrowserName(userAgent.getBrowser().getName());
        groupUv.setOsName(userAgent.getOperatingSystem().getName());
        groupUv.setDeviceType(userAgent.getOperatingSystem().getDeviceType().getName());
        return distributeUvDao.insertGroupUv(groupUv);
    }

    @Override
    public int insertLinkUv(String ip, UserAgent userAgent, DistributeLinkBO distributeLinkBO) {
        DistributeUv linkUv = new DistributeUv();
        linkUv.setCreateTime(DateUtils.currentTime());
        linkUv.setLoanDistributeGroupId(distributeLinkBO.getGroupId());
        linkUv.setLoanDistributeId(distributeLinkBO.getId());
        linkUv.setIp(ip);
        linkUv.setBrowserName(userAgent.getBrowser().getName());
        linkUv.setOsName(userAgent.getOperatingSystem().getName());
        linkUv.setDeviceType(userAgent.getOperatingSystem().getDeviceType().getName());
        return distributeUvDao.insertLinkUv(linkUv);
    }
}
